<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\Resource;

class InCodeResource extends Resource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {
        /** @var \App\Models\InCode $code */
        $code = $this;
        return [
            'id' => $code->id,
            'code' => $code->code,
            'created_user' => $code->user ? $code->user->name : '平台',
            'status' => $code->status == 0 ? '未使用' : '已使用',
            'used_user' => $code->used ? $code->used->name : '未使用',
            'created_at' => $code->created_at->toDateTimeString()
        ];
    }
}
